<?php
session_start();
isLogin();

if(isset($_POST["Submits"])){
	$fields=array('s_title','s_nick','s_level','s_cid','s_location','s_collect','s_perfect','s_shangcheng','s_clickurl');
	checkNotNull($fields,"?".$_SERVER['QUERY_STRING'],"店铺");
	if($_REQUEST['act']=='modify'){
		$sql=getUpdateSql($fields,'shoplist'," where s_id=".$_REQUEST['s_id']);
		$pre="修改";
	}else{
		$sql=getInsertSql($fields,"shoplist");
		$pre="添加";
	}
	if(mysql_query($sql)){
		reload_js($pre."成功","index.php?cmd=shop&order=s_id desc");
	}else{
		reload_js($pre."失败，原因：程序错误，请联系技术人员进行修改","index.php");
	}
}

$arr="";
if($_REQUEST['act']=='modify'){
	$arr=get_list_by_id('shoplist','s_id',$_REQUEST['s_id']);
	if(!$arr){
		reload_js("错误的参数s_id","?cmd=shop");
	}
}else if($_REQUEST['act']=='del'){
	$sql="delete from ".$prefix."shoplist where s_id=".$_GET['s_id'];
	$pre="删除";
	if(mysql_query($sql)){
		reload_js($pre."成功",$_SERVER['HTTP_REFERER']);
	}else{
		reload_js($pre."失败，原因：程序错误，请联系技术人员进行修改","index.php");
	}
}
?>
<script language="javascript" src="../templates/<?php echo $moban;?>/js/common.js"></script>
<script language="javascript">
changeWebTitle('店铺数据管理');
</script>

<div class="ContentRight">
    <div class="ContentRightTop">
      <div class="BarLeft"></div>
      <div class="ContentRightTopText">店铺数据管理
	  <?php 
	  if($_GET['act']==''){
	  	echo '<a href="?cmd='.$_REQUEST['cmd'].'&amp;act=add">（点此添加店铺）</a>';
	  }else{
	  	echo "<a href='".$_SERVER['HTTP_REFERER']."'>（返回）</a>";
	  }
	  ?>
	  </div>
      <div class="BarRight"></div>
      <div class="Cal"></div>
    </div>
  <div class="ContentRightBox">
	<?php if($_REQUEST['act']==''){?>
<table width="100%" cellpadding="0" class="Table1" bordercolor="#4ab902" border="1" cellspacing="0">
        <tr>
          <td height="25" colspan="5" align="center">信誉：&nbsp;&nbsp;1=1心&nbsp;&nbsp;&nbsp;&nbsp;6=1钻&nbsp;&nbsp;&nbsp;&nbsp;11=1蓝冠&nbsp;&nbsp;&nbsp;&nbsp;16=1皇冠&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		  <a href="<?php if(!urlstrip('order')){echo("?order=s_id desc");}
		  else{echo('?'.urlstrip("order")."&order=s_id desc");}?>">最近更新</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?cmd=shop">店铺数据管理首页</a></td>
        </tr>
        <tr>
          <td width="20%" align="center">掌柜名称</td>
          <td width="42%" height="25" align="center">店铺名称</td>
          <td width="9%" align="center">信誉</td>
          <td width="15%" align="center">类别</td>
          <td width="14%" align="center">操作</td>
        </tr>
		<?php 
		$page=$_REQUEST['page']?$_REQUEST['page']:1;
		$pagesize=10;
		$sqladd='where s_title ';
		if($_GET['key']==''){$sqladd.=" !='fs__fks____jk'";}else{$sqladd.=" like'%".$_GET['key']."%' or s_nick like'%".$_GET['key']."%'";}
		if($_GET['s_cid']!=''){
			$sqladd.="and s_cid=".$_GET['s_cid']." ";
		}
		if($_GET['s_level']!=''){
			$sqladd.="and s_level=".$_GET['s_level']." ";
		}
		$order="order by s_level desc";
		if($_GET['order']){$order="order by ".$_GET['order'];}
		$sql="select * from ".$prefix."shoplist ".$sqladd." ".$order." limit ".($page-1)*$pagesize.",".$pagesize;
		$result=mysql_query($sql);
		while($arr=mysql_fetch_array($result)){
		?>
		<tr>
          <td width="20%" align="center"><?php echo $arr['s_nick']?></td>
          <td width="42%" height="25" align="center">
		  <a href="<?php echo $arr['s_clickurl']?>" target="_blank">
		  <?php echo mysubstr($arr['s_title'],50,'..')?>
		  </a>	
		  </td>
          <td width="9%" align="center">
		  <a href="<?php if(!urlstrip('s_level')){echo("?s_level=".$arr['s_level']);}
		  else{echo('?'.urlstrip("s_level")."&s_level=".$arr['s_level']);}?>">
		  <?php echo $arr['s_level']?>
		  </a>
		  </td>
          <td width="15%" align="center">
		  <?php 
		  $sql="select * from ".$prefix."shopcat where s_cid=".$arr['s_cid'];
		  $re=mysql_query($sql);
		  if($a=mysql_fetch_array($re)){
			if(!urlstrip('s_cid')){echo("<a href='?s_cid=".$arr['s_cid']."'>");}
			else{echo('<a href="?'.urlstrip("s_cid")."&s_cid=".$arr['s_cid'].'">');}
		  	echo mysubstr($a['s_name'],16,'..');
			echo "</a>";
		  }
		  ?>
		  </td>
          <td width="14%" align="center"><a href="<?php echo "?cmd=".$_REQUEST['cmd']."&s_id=".$arr['s_id']."&act=modify"?>">修改</a>&nbsp;<a href="<?php echo "?cmd=".$_REQUEST['cmd']."&s_id=".$arr['s_id']."&act=del"?>" onclick="return confirm('您确认删除该条记录？删除后将不可恢复！');">删除</a></td>
        </tr>
		<?php
		}
		?>
        <tr>
          <td height="25" colspan="5" align="center">
		  <?php 
		  pagefy(get_list_count('shoplist',$sqladd),$pagesize,'');
		  echo $pagenav;
		  ?>		  </td>
        </tr>
        <tr>
          <td height="25" align="right">版权所有：</td>
          <td colspan="4"><a href="http://www.fengsh8.com" target="_blank">风尚淘客程序</a></td>
        </tr>
      </table>
    <?php }else{?>
	  <form action="" name="productform" method="post">
    <table width="100%" cellpadding="0" class="Table1" bordercolor="#4ab902" border="1" cellspacing="0">
        <tr>
          <td width="22%" height="25" align="right">店铺名称：</td>
          <td width="78%">
            <input name="s_title" type="text" id="s_title" value="<?php echo $arr['s_title'];?>" size="50"/></td>
        </tr>
        <tr>
          <td height="25" align="right">掌柜名称：</td>
          <td><input name="s_nick" type="text" id="s_nick" value="<?php echo $arr['s_nick'];?>" size="25"/></td>
        </tr>
        <tr>
          <td height="25" align="right">店铺信誉：</td>
          <td>
            <label>
            <select name="s_level" id="s_level">
			<?php
			for($i=1;$i<=20;$i++){
				if($i==$arr['s_level']){$s="selected";}else{$s='';}
				echo '<option value="'.$i.'" '.$s.'>'.$i.'</option>';
			}
			?>
            </select>
            1=1心&nbsp;&nbsp;&nbsp;&nbsp;6=1钻&nbsp;&nbsp;&nbsp;&nbsp;11=1蓝冠&nbsp;&nbsp;&nbsp;&nbsp;16=1皇冠 </label></td>
        </tr>
        <tr>
          <td height="25" align="right">店铺类别：</td>
          <td>
		   <select name="s_cid" id="s_cid">
		  <?php
		$sql="select * from ".$prefix."shopcat";
		$result=mysql_query($sql);
		while($a=mysql_fetch_array($result)){
			if($a['s_cid']==$arr['s_cid']){$s="selected";}else{$s='';}
			echo '<option value="'.$a['s_cid'].'" '.$s.'>'.$a['s_name'].'</option>';
		}
		  ?>
		  </select>
		  </td>
        </tr>
        <tr>
          <td height="25" align="right">地址：</td>
          <td>
            <input name="s_location" type="text" id="s_location" size="50" value="<?php echo $arr['s_location'];?>"/>
          请写明省市，例：浙江杭州</td>
        </tr>
        <tr>
          <td height="25" align="right">好评率：</td>
          <td>
            <input name="s_perfect" type="text" id="s_perfect" value="<?php echo $arr['s_perfect'];?>" size="25"/>
          精确到两位小数，例：98.24 , 后面不用加%</td>
        </tr>
        <tr>
          <td height="25" align="right">商城：</td>
          <td><p>
            <label>
              <input type="radio" name="s_shangcheng" value="1" <?php if($arr['s_shangcheng']){echo "checked";}?>/>
              是</label>
            <label>
              <input name="s_shangcheng" type="radio" value="0" <?php if(!$arr['s_shangcheng']){echo "checked";}?> />
              否</label>
            <br />
          </p></td>
        </tr>
        <tr>
          <td height="25" align="right">收藏量：</td>
          <td><input name="s_collect" type="text" id="s_collect" value="<?php echo $arr['s_collect'];?>" size="25"/>
          如果为商城店铺，收藏量填0即可</td>
        </tr>
        <tr>
          <td height="25" align="right">店铺链接：</td>
          <td><input name="s_clickurl" type="text" id="s_clickurl" value="<?php echo $arr['s_clickurl'];?>" size="50"/></td>
        </tr>
        <tr>
          <td height="25" align="right">&nbsp;</td>
          <td><input name="Submits" type="submit" id="Submits" value=" 提  交" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="Reset" type="reset" id="Reset" value=" 重 置 " />          </td>
        </tr>
      </table>
	  </form>
    <?php }?>
  </div>
    <div class="Cal"></div>
  </div>